package com.example.wisdomclassroomapi.domain.repository;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.wisdomclassroomapi.domain.entity.InfoLessonCarouselEntity;
import com.example.wisdomclassroomapi.infrastructure.mapper.InfoLessonCarouselMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;
/**
 * @Package: com.example.wisdomclassroomapi.domain.repository
 * @Description: <>
 * @Author: scholes
 * @CreateDate: 2022-04-18
 * @UpdateUser: scholes
 * @UpdateDate: 2022-04-18
 * @UpdateRemark: <>
 * @Version: 1.0
 */
@Repository
public class InfoLessonCarouselRepository {
    @Resource
    private InfoLessonCarouselMapper infoLessonCarouselMapper;

    public void add(InfoLessonCarouselEntity entity) {
       infoLessonCarouselMapper.insert(entity);
    }

    public InfoLessonCarouselEntity findById(String id) {
        return infoLessonCarouselMapper.selectById(id);
    }

    public int updateById(InfoLessonCarouselEntity entity) {
        return infoLessonCarouselMapper.updateById(entity);
    }

    public int deleteById(String id) {
        return infoLessonCarouselMapper.deleteById(id);
    }

    public IPage<InfoLessonCarouselEntity> page(InfoLessonCarouselEntity entity,IPage page) {
        QueryWrapper<InfoLessonCarouselEntity> wrapper = new QueryWrapper<>();
            if (StringUtils.isNotBlank(entity.getLessonId())){
            wrapper.eq("lesson_id",entity.getLessonId());
            }
            if (StringUtils.isNotBlank(entity.getUrl())){
            wrapper.eq("url",entity.getUrl());
            }
        return infoLessonCarouselMapper.selectPage(page, wrapper);
    }

    public List<InfoLessonCarouselEntity> list(InfoLessonCarouselEntity entity) {
        QueryWrapper<InfoLessonCarouselEntity> wrapper = new QueryWrapper<>();
            if (StringUtils.isNotBlank(entity.getLessonId())){
            wrapper.eq("lesson_id",entity.getLessonId());
            }
            if (StringUtils.isNotBlank(entity.getUrl())){
            wrapper.eq("url",entity.getUrl());
            }
        return infoLessonCarouselMapper.selectList(wrapper);
    }

}